﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Drawing;

using TreeSharp;

using Styx;
using Styx.Logic;
using Styx.Logic.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.Helpers;

namespace FelMaster.Classes.Deathknight
{
    public class FrostDps : TalentBase
    {
        public override string Name
        {
            get { return "Frost 1.01"; }
        }

        public override string KeySpell
        {
            get { return "Frost Strike"; }
        }

        public override Composite SingleRotation
        {
            get {
                return new PrioritySelector(
                    new Decorator(x => SC.PlayerIsChanneling, new TreeSharp.Action(a => SC.Log("Channeling"))),
                    SC.UseEngineerGloves(a => true, "Engineer's glove enchant"),
                    SC.CastSpell("Blood Fury", a => true, "Blood Fury"),
                    SC.CastSpell("Lifeblood", a => true, "Lifeblood"),
                    SC.CastSpell("Berserking", a => true, "Berserking"),
                    SC.CastSpell("Pillar of Frost", a => true, "Pillar of Frost"),
                    SC.CastSpell("Blood Tap", a => Me.DeathRuneCount == 0, "Blood Tap"),
                    SC.CastSpell("Raise Dead", a => (Me.Pet == null || Me.Pet.Dead) && Me.CurrentTarget.CurrentHealth > 1000000, "Raise Dead"),
                    SC.CastSpell("Outbreak", a => SC.TargetDebuffTimeLeft("Blood Plague") < 2 || SC.TargetDebuffTimeLeft("Frost Fever") < 2, "Outbreak"),
                    SC.CastSpell("Howling Blast", a => SC.TargetDebuffTimeLeft("Frost Fever") < 2, "Howling Blast"),
                    SC.CastSpell("Plague Strike", a => SC.TargetDebuffTimeLeft("Blood Plague") < 2, "Plague Strike"),
                    SC.CastSpell("Obliterate", a => Me.DeathRuneCount > 1 && Me.FrostRuneCount > 1 && Me.UnholyRuneCount > 1, "Obliterate"),
                    SC.CastSpell("Obliterate", a => (Me.DeathRuneCount == 2 && Me.FrostRuneCount == 2) || (Me.DeathRuneCount == 2 && Me.UnholyRuneCount == 2) || (Me.FrostRuneCount == 2 && Me.UnholyRuneCount == 2), "Obliterate"),
                    SC.CastSpell("Frost Strike", a => Me.CurrentRunicPower >= 110, "Frost Strike"),
                    SC.CastSpell("Howling Blast", a => SC.PlayerHasBuff("Freezing Fog"), "Howling Blast"),
                    SC.CastSpell("Obliterate", a => (Me.DeathRuneCount == 2 || Me.FrostRuneCount == 2 || Me.UnholyRuneCount == 2), "Obliterate"),
                    SC.CastSpell("Frost Strike", a => Me.CurrentRunicPower >= 100, "Frost Strike"),
                    new Decorator(
                        ret => Me.GotTarget && SC.CanCast("Death and Decay") && SC.CountEnnemiesInRange(Me.CurrentTarget.Location, 18) > 3,
                        new Sequence(
                            new TreeSharp.Action(ret => SC.CastSpell("Death and Decay")),
                            new TreeSharp.Action(ret => Styx.Logic.Combat.LegacySpellManager.ClickRemoteLocation(WoWMathHelper.CalculatePointFrom(Me.Location, Me.CurrentTarget.Location,Math.Max(0, Me.CombatReach+0.33333f + Me.CurrentTarget.CombatReach) - 3f)))
                        )
                    ),
                    SC.CastSpell("Obliterate", a => true, "Obliterate"),
                    SC.CastSpell("Empower Rune Weapon", a => Me.CurrentTarget.CurrentHealth > 3000000, "Empower Rune Weapon"),
                    SC.CastSpell("Frost Strike", a => true, "Frost Strike"),
                    SC.CastSpell("Howling Blast", a => true, "Howling Blast"),
                    SC.CastSpell("Empower Rune Weapon", a => Me.DeathRuneCount == 0 && Me.UnholyRuneCount == 0 && Me.FrostRuneCount == 0, "Empower Rune Weapon"),
                    SC.CastSpell("Horn of Winter", a => true, "Horn of Winter")
                );
            }
        }

        public override Composite Buffs
        {
            get
            {
                return new PrioritySelector(
                    //XXX put your buff rotation here!
                    
                );
            }
        }

        public override Composite PVPRotation
        {
            get { throw new NotImplementedException(); }
        }

        public override Composite PVERotation
        {
            get
            {
                return SingleRotation;
            }
        }
    }
}
